using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AddStatusEffect:MonoBehaviour {

	public string statusType;
	public float amount;
	public float amountPerDamage;
	Projectile projectile;

	private void Awake() {
		projectile=GetComponent<Projectile>();
	}

	private void OnEnable() {
		ModifierApplyStatusEffect newModifier = new ModifierApplyStatusEffect(projectile,new string[0]);
		newModifier.buffType=System.Reflection.TypeInfo.GetType(statusType);
		newModifier.amount=amount;
		newModifier.amountPerDamage=amountPerDamage;
		projectile.AddModifier(newModifier);
	}


}

public class ModifierApplyStatusEffect:ProjectileModifier {

	public override ProjectileModifier Clone(Projectile owner) {
		ModifierApplyStatusEffect result = new ModifierApplyStatusEffect(owner,new string[0]);
		result.buffType=buffType;
		result.amount=amount;
		result.amountPerDamage=amountPerDamage;
		return result;
	}

	public ModifierApplyStatusEffect(Projectile owner,string[] args) : base(owner,args) {

	}

	public System.Type buffType;
	public float amount;
	public float amountPerDamage;
	public float minDamage;
	public float maxAmount=float.MaxValue;

	protected override void SubscribeEvents() {
		base.SubscribeEvents();
		MobEventHelper.damaged.SubscribeSingleDamagerProjectile(owner,Mob_Damaged);
	}
	protected override void UnsubscribeEvents() {
		base.UnsubscribeEvents();
		MobEventHelper.damaged.UnsubscribeSingleDamagerProjectile(owner,Mob_Damaged);
	}


	void Mob_Damaged(object _sender,DamageEventArgs e) {
		if(e.stat.amount<=Mathf.Max(0,minDamage)) return;
		if(e.stat.isComposition) return;
		Mob sender = _sender as Mob;
		sender.buffs[buffType].stacks+=Mathf.Clamp(amount+amountPerDamage*e.stat.amount,0,maxAmount);
	}

}